import { defineStore } from 'pinia'
import { reqC1, reqC2, reqC3 } from '@/api/product/attr/index'
import type { categoryResponseData } from '@/api/product/type'
import type { categoryState } from './types'
const useCategoryStore = defineStore('Category', {
  state: (): categoryState => {
    return {
      C1Arr: [],
      C2Arr: [],
      C3Arr: [],
      C1Id: '',
      C2Id: '',
      C3Id: '',
    }
  },
  actions: {
    async getC1() {
      const result: categoryResponseData = await reqC1()
      if (result.code == 200) {
        this.C1Arr = result.data
      }
    },
    async getC2() {
      const result: categoryResponseData = await reqC2(this.C1Id)
      if (result.code == 200) {
        this.C2Arr = result.data
      }
    },
    async getC3() {
      const result: categoryResponseData = await reqC3(this.C2Id)
      if (result.code == 200) {
        this.C3Arr = result.data
      }
    },
  },
  getters: {},
})

export default useCategoryStore
